<template>
  <div>
    <SearchTable
      v-bind="$attrs"
      :searchSchame="searchSchame"
      :tableColumns="tableColumns"
      :api="queryMatterProcessStatisticList"
      :dealSearchParams="dealSearchParams"
      :defaultQuery="defaultQuery"
      :query="{ taskType }"
      ref="tableRef"
    ></SearchTable>
    <FollowDialog ref="followDialog" />
  </div>
</template>

<script lang="ts" setup>
import { computed, useTemplateRef } from 'vue'
import SearchTable from '@/components/table/SearchTable.vue'
import {
  generateTableColumn,
  dealSearchParams,
  searchSchame,
  EEassignStr,
} from './util'
import { queryMatterProcessStatisticList } from '@/api/home'
import FollowDialog from '@/views/mission/follow/FollowDialog.vue'
import { useRouteQuery } from '@vueuse/router'

const defaultStatus = useRouteQuery('status', '', {
  transform: Number,
})

withDefaults(defineProps<{ taskType: string }>(), {
  taskType: EEassignStr[1],
})

const defaultQuery = computed(() => {
  return {
    matterStatus: defaultStatus.value ? defaultStatus.value : undefined,
  }
})

const followDialog =
  useTemplateRef<InstanceType<typeof FollowDialog>>('followDialog')

const tableColumns = generateTableColumn(tableColumnClick)

// 列表项点击
function tableColumnClick(columnType: string, row: Record<string, any>) {
  if (columnType === 'matterTitle') {
    row.matterId = row.id
    followDialog?.value.show(row)
  }
}
</script>
